package targetToOffer.eigthDay;

import java.util.LinkedList;

/**
 * @author Godc
 * @description
 */
public class Exchange {
    public static void main(String[] args) {
        ExchangeSolution s = new ExchangeSolution();
        s.exchange(new int[]{1,2,3,4});
    }
}
class ExchangeSolution {
    /**
     * @param nums
     * @return
     */
    public int[] exchange(int[] nums) {
        if(nums.length==0) return nums;
        int i = 0,j = nums.length-1;
        while(i<j){
            // 从左找第一个奇数
            while (i<j&&nums[i]%2!=0) i++;
            while (i<j&&nums[j]%2==0) j--;
            int t = nums[i];
            nums[i] = nums[j];
            nums[j] = t;
        }
        return nums;
    }
}
